import { RegisterComponent } from "@feng3d/ecs";
import { CubeCamera } from "../../thirdparty/three/imports";
import { Component3D } from "../core/Component3D";
import { WebGLCubeRenderTarget3D } from "../renderers/WebGLCubeRenderTarget3D";
import { WebGLRenderer3D } from "../renderers/WebGLRenderer3D";
import { Scene3D } from "../scenes/Scene3D";

declare module "@feng3d/ecs"
{
    interface ComponentMap { CubeCamera3D: CubeCamera3D; }
}

/**
 * 包装`three`中`CubeCamera`。
 */
@RegisterComponent({ name: 'CubeCamera3D' })
export class CubeCamera3D extends Component3D
{
    /**
     * @private
     */
    _camera: CubeCamera;

    near: number;
    far: number;
    renderTarget: WebGLCubeRenderTarget3D;

    init(): void
    {
        this._camera = new CubeCamera(this.near, this.far, this.renderTarget._target);
        this.entity._group.add(this._camera);

        super.init();
    }

    destroy(): void
    {
        this.entity._group.remove(this._camera);
        this._camera = null;

        super.destroy();
    }

    update(renderer: WebGLRenderer3D, scene: Scene3D)
    {
        this._camera.update(renderer._webGLRenderer, scene._scene);
    }
}
